package com.xdog.web3.domain.twitter;

import lombok.Data;
import java.util.List;

@Data
public class TwitterResponse {
    // 新API结构字段
    private DataContainer data;
    private List<Entry> entries;
    private List<TweetData> tweetDataList; // 添加这个字段来处理简化格式

    @Data
    public static class DataContainer {
        private SearchByRawQuery search_by_raw_query;
        private List<TweetData> data;  // 将data字段添加到DataContainer中
    }

    @Data
    public static class SearchByRawQuery {
        private SearchTimeline search_timeline;
    }

    @Data
    public static class SearchTimeline {
        private Timeline timeline;
    }

    @Data
    public static class Timeline {
        private List<Instruction> instructions;
    }

    @Data
    public static class Instruction {
        private String type;
        private List<Entry> entries;
    }

    @Data
    public static class Entry {
        private String entryId;
        private String sortIndex;
        private Content content;
        private ModuleContent moduleContent; // 用于用户模块
    }

    @Data
    public static class Content {
        private String entryType;
        private String __typename;
        private ItemContent itemContent;
        private ModuleContent content; // 用于用户模块
        private String cursorType;
        private String value;
        private Header header;
        private Footer footer;
        private ClientEventInfo clientEventInfo;
        private ModuleContent moduleContent; // 添加这个字段
    }

    @Data
    public static class ModuleContent {
        private String entryType;
        private String __typename;
        private List<Item> items;
        private String displayType;
        private Header header;
        private Footer footer;
        private ClientEventInfo clientEventInfo;
    }

    @Data
    public static class Item {
        private String entryId;
        private ItemDetails item;
    }

    @Data
    public static class ItemDetails {
        private ItemContent itemContent;
        private ClientEventInfo clientEventInfo;
    }

    @Data
    public static class ItemContent {
        private String itemType;
        private String __typename;
        private UserResults user_results;
        private TweetResults tweet_results;
        private UserDisplayType userDisplayType;
    }

    @Data
    public static class UserResults {
        private Result result;
    }

    @Data
    public static class TweetResults {
        private TweetResult result;
    }

    @Data
    public static class TweetResult {
        private String __typename;
        private String rest_id;
        private Core core;
        private EditControl edit_control;
        private Views views;
        private String source;
        private NoteTweet note_tweet; // 添加这个字段
        private Boolean grok_analysis_button;
        private Legacy legacy;
        private Object unmention_data; // 改为Object类型以处理不同数据格式
        private Boolean is_translatable;
        private String created_at; // 添加这个字段
        private String conversation_id_str; // 添加这个字段
        private int reply_count; // 添加这个字段
        private int retweet_count; // 添加这个字段
        private int favorite_count; // 添加这个字段
        private int quote_count; // 添加这个字段
        private Entities entities; // 添加这个字段
        private ExtendedEntities extended_entities; // 添加这个字段
        private Boolean bookmarked; // 添加这个字段
        private int bookmark_count; // 添加这个字段
        private List<Integer> display_text_range; // 添加这个字段
    }

    @Data
    public static class Result {
        private String __typename;
        private String id;
        private String rest_id;
        private Object affiliates_highlighted_label; // 改为Object类型以处理不同数据格式
        private Boolean has_graduated_access;
        private Boolean is_blue_verified;
        private Legacy legacy;
        private Object location; // 改为Object类型以处理不同数据格式
        private Object parody_commentary_fan_label; // 改为Object类型以处理不同数据格式
        private String profile_image_shape;
        private Object privacy; // 改为Object类型以处理不同数据格式
        private Object tipjar_settings; // 改为Object类型以处理不同数据格式
        private Object verification; // 改为Object类型以处理不同数据格式
        private Professional professional;
    }

    @Data
    public static class AffiliatesHighlightedLabel {
        // 空对象
        private String value; // 添加value字段以处理字符串情况
    }

    @Data
    public static class ParodyCommentaryFanLabel {
        private String value;
        private Object fan_label; // 添加fan_label字段以处理不同数据格式
    }

    @Data
    public static class Privacy {
        private Boolean protectedField; // 使用protectedField因为protected是关键字
        private String value; // 添加value字段以处理字符串情况
    }

    @Data
    public static class Verification {
        private Boolean verified;
        private String value; // 添加value字段以处理字符串情况
    }

    @Data
    public static class TipjarSettings {
        private Boolean is_enabled;
        private String value; // 添加value字段以处理字符串情况
    }

    @Data
    public static class Location {
        private String location;
        private String value; // 添加value字段以处理字符串情况
    }

    @Data
    public static class Professional {
        private String rest_id;
        private String professional_type;
        private List<Category> category;
    }

    @Data
    public static class Category {
        private int id;
        private String name;
        private String icon_name;
    }

    @Data
    public static class Core {
        private UserResults user_results;
    }

    @Data
    public static class EditControl {
        private List<String> edit_tweet_ids;
        private String editable_until_msecs;
        private Boolean is_edit_eligible;
        private String edits_remaining;
    }

    @Data
    public static class Views {
        private String count;
        private String state;
    }

    @Data
    public static class UnmentionData {
        // 空对象
    }

    @Data
    public static class Legacy {
        private int bookmark_count;
        private Boolean bookmarked;
        private String created_at;
        private List<Integer> display_text_range;
        private Entities entities;
        private ExtendedEntities extended_entities;
        private int favorite_count;
        private Boolean favorited;
        private String full_text;
        private Boolean is_quote_status;
        private String lang;
        private Boolean possibly_sensitive;
        private Boolean possibly_sensitive_editable;
        private int quote_count;
        private int reply_count;
        private int retweet_count;
        private Boolean retweeted;
        private String user_id_str;
        private String id_str;
        private Boolean following;
        private Boolean can_dm;
        private Boolean can_media_tag;
        private Boolean default_profile;
        private Boolean default_profile_image;
        private String description;
        private Entities user_entities;
        private int fast_followers_count;
        private int favourites_count;
        private int followers_count;
        private int friends_count;
        private Boolean has_custom_timelines;
        private Boolean is_translator;
        private int listed_count;
        private String location;
        private int media_count;
        private String name;
        private int normal_followers_count;
        private List<String> pinned_tweet_ids_str;
        private String profile_banner_url;
        private String profile_image_url_https;
        private String profile_interstitial_type;
        private String screen_name;
        private int statuses_count;
        private String translator_type;
        private String url;
        private Boolean verified;
        private Boolean want_retweets;
        private List<String> withheld_in_countries;
    }

    @Data
    public static class Entities {
        private List<Hashtag> hashtags;
        private List<Media> media;
        private List<Symbol> symbols;
        private List<Timestamp> timestamps;
        private List<Url> urls;
        private List<UserMention> user_mentions;
        private Urls url;
        private Urls description;
    }

    @Data
    public static class ExtendedEntities {
        private List<Media> media;
    }

    @Data
    public static class Hashtag {
        private List<Integer> indices;
        private String text;
    }

    @Data
    public static class Media {
        private String display_url;
        private String expanded_url;
        private String id_str;
        private List<Integer> indices;
        private String media_key;
        private String media_url_https;
        private String type;
        private String url;
        private ExtMediaAvailability ext_media_availability;
        private Features features;
        private Sizes sizes;
        private OriginalInfo original_info;
        private MediaResults media_results;
    }

    @Data
    public static class Symbol {
        private List<Integer> indices;
        private String text;
    }

    @Data
    public static class Timestamp {
        private List<Integer> indices;
        private String text;
    }

    @Data
    public static class Url {
        private List<Integer> indices;
        private String display_url;
        private String expanded_url;
        private String url;
    }

    @Data
    public static class Urls {
        private List<Url> urls;
    }

    @Data
    public static class UserMention {
        private List<Integer> indices;
        private String screen_name;
        private String name;
        private String id_str;
    }

    @Data
    public static class ExtMediaAvailability {
        private String status;
    }

    @Data
    public static class Features {
        private Large large;
        private Medium medium;
        private Small small;
        private Orig orig;
    }

    @Data
    public static class Large {
        private List<Face> faces;
    }

    @Data
    public static class Medium {
        private List<Face> faces;
    }

    @Data
    public static class Small {
        private List<Face> faces;
    }

    @Data
    public static class Orig {
        private List<Face> faces;
    }

    @Data
    public static class Face {
        private int x;
        private int y;
        private int h;
        private int w;
    }

    @Data
    public static class Sizes {
        private Size large;
        private Size medium;
        private Size small;
        private Size thumb;
    }

    @Data
    public static class Size {
        private int h;
        private int w;
        private String resize;
    }

    @Data
    public static class OriginalInfo {
        private int height;
        private int width;
        private List<FocusRect> focus_rects;
    }

    @Data
    public static class FocusRect {
        private int x;
        private int y;
        private int h;
        private int w;
    }

    @Data
    public static class MediaResults {
        private String media_key;
    }

    @Data
    public static class UserDisplayType {
        private String value;
    }

    @Data
    public static class Header {
        private String displayType;
        private String text;
        private Boolean sticky;
    }

    @Data
    public static class Footer {
        private String displayType;
        private String text;
        private LandingUrl landingUrl;
    }

    @Data
    public static class LandingUrl {
        private String url;
        private String urlType;
    }

    @Data
    public static class ClientEventInfo {
        private String component;
        private String element;
        private Details details;
    }

    @Data
    public static class Details {
        private TimelinesDetails timelinesDetails;
    }

    @Data
    public static class TimelinesDetails {
        private String controllerData;
    }

    // 为了兼容前端现有代码，添加简化数据结构
    private Meta meta;
    private List<Error> errors;

    @Data
    public static class TweetData {
        private String id;
        private String text;
        private String created_at;
        private String author_id;
        private PublicMetrics public_metrics;
        private UserData user;
        private String url; // 推文链接

        @Data
        public static class PublicMetrics {
            private int retweet_count;
            private int reply_count;
            private int like_count;
            private int quote_count;
            private int view_count; // 浏览量
        }

        @Data
        public static class UserData {
            private String id;
            private String name;
            private String username;
            private String profile_image_url;
        }
    }

    @Data
    public static class Meta {
        private String newest_id;
        private String oldest_id;
        private int result_count;
        private String next_token;
    }

    @Data
    public static class Error {
        private String value;
        private String detail;
        private String title;
        private String resource_type;
        private String parameter;
        private String resource_id;
        private int status;
    }
    
    /**
     * 合并不同API的数据到统一格式
     * @param source 来源API标识 (api1, api2, api3, api4)
     */
    public void mergeFromSource(String source) {
        // 根据不同的API源进行数据转换和统一
        // 这里可以添加特定于API的处理逻辑
        // 目前保持通用处理
    }
    
    @Data
    public static class NoteTweet {
        private Boolean is_expandable;
        private NoteTweetResult note_tweet_results;
    }

    @Data
    public static class NoteTweetResult {
        private String id;
        private String text;
        private EntitySet entity_set;
    }

    @Data
    public static class EntitySet {
        private List<String> hashtags;
        private List<String> symbols;
        private List<String> timestamps;
        private List<String> urls;
        private List<UserMentionInNote> user_mentions;
    }

    @Data
    public static class UserMentionInNote {
        private String id_str;
        private String name;
        private String screen_name;
        private List<Integer> indices;
    }
}